package coupon

import (
	"gorm.io/gorm"
	"shop/database/mysql"
)

type Rule struct {
	gorm.Model
	UserID    int64  `json:"user-id" gorm:"type:int(11);not null"`
	ImageUrl  string `json:"image_url" gorm:"type:varchar(255);column:image_url"`
	Title     string `json:"title" gorm:"type:varchar(50);comment:标题"`
	Introduce string `json:"introduce" gorm:"type:varchar(100);comment:详情"`
	Moment    string `json:"moment" gorm:"type:varchar(30);comment:过期时间"`
	Price     string `json:"price" gorm:"type:varchar(20);comment:优惠价格"`
}

func (r *Rule) RuleList() (info []Rule, err error) {
	return info, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Table("rules").Find(&info).Error
	})
}
